package controller.cartp;

import com.alibaba.fastjson.JSON;
import com.zuche.framework.tradingPlatform.CurrenceSource;
import com.zuche.framework.tradingPlatform.RequestParams;
import com.zuche.framework.utils.PropertiesReader;
import controller.constant.CarTpConstant;
import controller.enums.GroupTypeEnum;
import controller.remote.CartpRemoteClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**银联rpc接口测试类
 * Created by 雷霆 on 2016/10/18.
 */
@Controller
@RequestMapping(value = "zuche/unionPay",produces = "text/html;charset=utf-8")
public class ZucheTestController {
    private static final Logger logger = LoggerFactory.getLogger(ZucheTestController.class);

    private String projectAddress;

    public ZucheTestController() {
        this.projectAddress = PropertiesReader.getAppointPropertiesAttribute(
                "setting", "projectAddress", String.class);
    }


    @RequestMapping(value = "receive.do_")
    public static  Object receive(){
        Map<String, String> callBackMap=new HashMap<String, String>();
        callBackMap.put("params","5E1E59832A4EFFCB28A5DA2D95258B7D76B953C95AC398971C87F2AB59C313B89FC1BDA966E31FFEAA237E0DA74F7EBFA34F597F5ACF09D1E08201B675F012BC05E4BA46781B888C62542BE2E9C0D1B468AE3D89CBC798B0F2C35A2F2A899CCDFFD9D961D4B463C740D084DC0C9BCD90EA10B338B0BF2B308E6A0ED314DC46C69BA8D89B882554F2C6AE5C0370B404A3C6423E013FBCCD5E752EC22761C3B2D85DBC24B9C6A9AD6758E2A404E736C3224FD625E615278327FA82DDFB94D50142340BAC98A5FC50303FB81793A3D02D8F28A5DA2D95258B7D6D494C440848E6B47EEA4826244997744735C1F06F51C19C6B0E9AE3EDEB802F47874400C339293F328B81DBEFC4571FC26BE732A71C94177A0400043D1023D473C98D7CFCA4A8B77737DA9BE9F7271C761B643559764F6C7A7E2E9BE254D0D4979553559ABA6D223A105F16DBC809930C276F784553A98EF5EDFFBC43089AD759EE4D50194EBA8F09CE0CE2D89B6FE96F6369A1FC995F5F1A8509D82BABFC3DE4EDD35D3D1453A60EF61874AF3EAA0B0DAD7A0E4E788EF037128C3CFB36D11C16353EB42E8EB9EEA8A13132F05D9AE8E38B67BCA37AFA4A9AF2B25A626360340B57D5C2D5269DE58F752F104FFBCEA0FFED310CB9A8EB98BD7ACB00853DEE808943CA6A908704906F7C43F03E2BD53DDA7494335F46BF06FB2425675044DE76B3B4BBB10E31EAB268DAFC127A784E6583D186249893C6D7C0B4FFD7C6E52AC21C2564C053ADAB0D382B41F0E34C2416311C42EEA07CF963D5B7A1FD560296E8");
        callBackMap.put("signature","");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(callBackMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(callBackMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }







    /**
     * 绑卡查询
     * @return
     */
    @RequestMapping(value = "doQueryCreditcardBind.do_")
    public static  Object doQueryCreditcardBind(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.QUERY_CREDITCARD_BIND.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.QUERY_CREDITCARD_BIND.getKey());
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.PAYER_ID, "10676733");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }


    /**
     * 查询卡信息
     * @param request
     * @param response
     */
    @RequestMapping("/unionCardInfo.do_")
    public void unionCardInfo(HttpServletRequest request,
                                  HttpServletResponse response) {
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.QUERY_UNION_CARD_INFO.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.QUERY_UNION_CARD_INFO.getKey());
        requestMap.put(RequestParams.CARD_NO,"5240470019132178");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }

    /**
     * 查询卡信息
     * @param request
     * @param response
     */
    @RequestMapping("/queryCreditcardBind.do_")
    public void queryCreditcardBind(HttpServletRequest request,
                                  HttpServletResponse response) {
        // 6225758319641493
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.GROUP_TYPE, GroupType.QUERY_CARD_INFO);
        paramMap.put(RequestParams.SYS_GROUP, "0");
        paramMap.put(RequestParams.CARD_NO,"6217920660398566");
        paramMap.put(RequestParams.CARD_TYPE,"2");
        paramMap.put("tp_is_driver","true");
        paramMap.put("tp_identity_type","0");
        logger.error(" [carttp调用参数] : " + paramMap.toString());
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, false);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }


    /**
     * 查询卡信息块钱
     * @param request
     * @param response
     */
    @RequestMapping("/testQueryCardInfo.do_")
    public void testQueryCardInfo(HttpServletRequest request,
                                  HttpServletResponse response) {
        // 6225758319641493
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.GROUP_TYPE, GroupType.QUERY_CARD_INFO);
        paramMap.put(RequestParams.SYS_GROUP, "0");
        paramMap.put(RequestParams.CARD_NO,"6217920660398566");
        paramMap.put(RequestParams.CARD_TYPE,"2");
        paramMap.put("tp_is_driver","true");
        paramMap.put("tp_identity_type","0");
        logger.error(" [carttp调用参数] : " + paramMap.toString());
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, false);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }
    /**
     * 查询银联卡信息  银联
     * @param request
     * @param response
     */
    @RequestMapping("/testQueryUnionCardInfo.do_")
    public void testQueryUnionCardInfo() {
        // 6225758319641493
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.GROUP_TYPE,"unionCardInfo");
        paramMap.put(RequestParams.SYS_GROUP, "0");
        paramMap.put(RequestParams.CARD_NO,"6217920660398566");
        //paramMap.put("tp_is_query_support","1");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));
    }


    @RequestMapping(value = "doSendSms.do_")
    public static  Object doSendSms(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, "ICBC");
        requestMap.put(RequestParams.IS_VALIDATE, "true");
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_SEND_SMS.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_SEND_SMS.getKey());
        //  requestMap.put(RequestParams.BUSINESS_ID, "1001010000002");
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.PAYER_ID, "10676733");
        //requestMap.put(RequestParams.CARD_NO, "6217900100019858094");
        requestMap.put(RequestParams.CARD_TYPE, "2");
       // requestMap.put(RequestParams.IDENTITY_ID, "131082198602210525");
        requestMap.put(RequestParams.IDENTITY_TYPE, "0");
       // requestMap.put(RequestParams.PAYER_NAME, "荣雪梅");
        //requestMap.put(RequestParams.PAYER_TEL, "13691275856");
        requestMap.put(RequestParams.CARD_NO, "6217920660398566");
        requestMap.put(RequestParams.IDENTITY_ID, "652323199107043516");
        requestMap.put(RequestParams.PAYER_TEL, "15301067848");
        requestMap.put(RequestParams.PAYER_NAME, "雷霆");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    @RequestMapping(value = "doPayBind.do_")
    public static  Object doPayBind(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CurrenceSource.SPDB);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_PAY_BIND.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_PAY_BIND.getKey());
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.PAYER_ID, "10676733");
        requestMap.put(RequestParams.VALID_CODE, "851400");
        requestMap.put(RequestParams.IS_VALIDATE, "true");
        requestMap.put(RequestParams.RECORD_ID, "030027343502607506");
        requestMap.put(RequestParams.BIND_ID, "33069");
        requestMap.put(RequestParams.CARD_TYPE, "2");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    /**
     * 直接消费
     * @return
     */
    @RequestMapping(value = "doPayment.do_")
    public static  Object doPayment(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_PAYMENT.getValue());
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.PAYER_ID, "10676733");
        requestMap.put(RequestParams.BIND_ID, "33069");
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_PAYMENT.getKey());
        requestMap.put(RequestParams.BUSINESS_ID,"030027343502607425");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    /**
     * 消费退款
     * @return
     */
    @RequestMapping(value = "doRefund.do_")
    public static  Object doRefund(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_CANCEL.getValue());
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.RECORD_ID, "030027343502607425");
        requestMap.put(RequestParams.BUSINESS_ID,"11111111");
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_CANCEL.getKey());

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    /**
     * 消费撤销
     * @return
     */
    @RequestMapping(value = "doCancel.do_")
    public static  Object doCancel(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_FCAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_CANCEL.getValue());
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.RECORD_ID, "00427335162100272");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }


    /**
     * 网页支付 web
     * @return
     */
    @RequestMapping(value = "doWebPay.do_")
    public static  Object doWebPay(HttpServletRequest request,
                                   HttpServletResponse response){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_WEB_PAY.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_WEB_PAY.getKey());
        requestMap.put(RequestParams.BUSINESS_ID, "11111");
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL,"www.baidu.com");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
         CartpRemoteClient.doMvc(request, response, requestMap, true);
       // logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return null;
    }



    /**
     * 网页支付 wap
     * @return
     */
    @RequestMapping(value = "doWapPay.do_")
    public static  Object doWapPay(HttpServletRequest request,
                                   HttpServletResponse response){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_WAP_PAY.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_WAP_PAY.getKey());
        requestMap.put(RequestParams.BUSINESS_ID, "11111");
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL,"www.baidu.com");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        CartpRemoteClient.doMvc(request, response, requestMap, true);
        // logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return null;
    }

    /**
     * 网页支付
     * @return
     */
    @RequestMapping(value = "doAPPPay.do_")
    public static  Object doAPPPay(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_UCAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNION_APP_PAY.getValue());
        requestMap.put(RequestParams.BUSINESS_NAME, GroupTypeEnum.UNION_APP_PAY.getKey());
        requestMap.put(RequestParams.BUSINESS_ID, "11111");
        requestMap.put(RequestParams.BUSINESS_MONEY,"0.01");
        requestMap.put(RequestParams.ASYNC_REPLY_URL,"www.baidu.com");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }


    /**
     * 解绑
     * @return
     */
    @RequestMapping(value = "doUnbindCreditCard.do_")
    public static  Object doUnbindCreditCard(){
        Map<String,String> requestMap=new HashMap<String, String>();
        requestMap.put(RequestParams.SYS_GROUP, CarTpConstant.SYS_GROUP_CAR);
        requestMap.put(RequestParams.SOURCE_ID, CarTpConstant.SOURCE_ID);
        requestMap.put(RequestParams.GROUP_TYPE, GroupTypeEnum.UNBIND_CREDIT_CARD.getValue());
        requestMap.put(RequestParams.ASYNC_REPLY_URL, "wwww.baidu.com");
        requestMap.put(RequestParams.BIND_ID, "33069");

        logger.error(" [carttp调用参数] : " + JSON.toJSONString(requestMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(requestMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

        return resultMap;
    }

    /**
     * 快钱支持银行
     * @return
     */
    @RequestMapping("/testQuerySupport.do_")
    @ResponseBody
    public void testQuerySupport(){
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.SYS_GROUP, "1");
        paramMap.put(RequestParams.CARD_TYPE,"1");//1,一键支付2,网银
        paramMap.put(RequestParams.GROUP_TYPE,GroupType.QUERY_SUPPORT);
        paramMap.put(RequestParams.TARGET_GROUP,GroupType.UNION_SMS_PAY);
//        paramMap.put(RequestParams.TARGET_GROUP,"easyLinkWebPay");
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

    }


    /**
     * 查询-用户PCI绑卡信息
     * @return
     */
    @RequestMapping("/testPCIQuery.do_")
    @ResponseBody
    public void testPCIQuery(){
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put(RequestParams.SYS_GROUP, "0");
        paramMap.put(RequestParams.CARD_TYPE,"1");
        paramMap.put(RequestParams.PAYER_ID,"10676342");
        paramMap.put(RequestParams.GROUP_TYPE,GroupType.PCI_QUERY);
        logger.error(" [carttp调用参数] : " + JSON.toJSONString(paramMap));
        Map<String,String> resultMap = CartpRemoteClient.doRpcInvoke(paramMap, true);
        logger.error(" [carttp返回结果] : " + JSON.toJSONString(resultMap));

    }

}
